package com.lin.controller;

import com.lin.entity.Parcel;
import com.lin.service.IParcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/parcel")
@CrossOrigin(origins = "*")
public class ParcelController {
    @Autowired
    IParcelService iParcelService;


    @GetMapping(value = "/info",produces = {"application/json;charset=UTF-8"})
    public List<Parcel> listParcelInfo(){
        return iParcelService.listParcel();
    }


    @GetMapping(value = "/info/{id}",produces = {"application/json;charset=UTF-8"})
    public Parcel ParcelInfoById(@PathVariable(value = "id")Integer id){
        return iParcelService.selectParcelById(id);
    }


    @PostMapping(value = "/add",produces = {"application/json;charset=UTF-8"})
    public void addParcel(@RequestBody Parcel parcel){
        iParcelService.insertParcel(parcel);
    }


    @PostMapping(value = "/remove/{id}",produces = {"application/json;charset=UTF-8"})
    public void removeParcel(@PathVariable("id") Integer id){
        iParcelService.deleteParcelById(id);
    }


    @PostMapping(value = "/edit",produces = {"application/json;charset=UTF-8"})
    public void editParcel(@RequestBody Parcel parcel
    ){
        iParcelService.updateParcel(parcel);
    }

}